import request from './request'
import { useUserStore } from "../store/modules/user"
// 获取用户列表
export function getUsersList(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/getList',
        method: 'post',
        headers: token,
        data,
    })
}

// 导出客户数据
export function userExportExcel(data: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/dataExport/userExportExcel',
        method: 'post',
        headers: token,
        data,
        responseType: 'blob'
    })
}

// 新增或修改用户
export function addUser(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/add',
        method: 'post',
        headers: token,
        data,
    })
}

// 批量更改用户状态
export function changeStatus(data: object, status: boolean) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/status',
        method: 'put',
        headers: token,
        data,
        params: { status }
    })
}

// 批量删除用户
export function deleteUser(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/',
        method: 'delete',
        headers: token,
        data,
    })
}

// 分页获取用户级别下拉数据列表
export function levelPageSelect(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/select/user/levelPageSelect',
        method: 'post',
        headers: token,
        data,
    })
}

// 分页获取用户分类下拉数据列表
export function typePageSelect(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/select/user/typePageSelect',
        method: 'post',
        headers: token,
        data,
    })
}

// 获取用户账号信息
export function getUserInfo(id: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/' + id,
        method: 'get',
        headers: token
    })
}

// 获取用户联系人列表
export function getUserContact(data: any, id: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/contact/getUserContact/' + id,
        method: 'post',
        headers: token,
        data
    })
}

// 新增或修改联系人
export function saveUserContact(data: any, id: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/contact/save/' + id,
        method: 'post',
        headers: token,
        data
    })
}

// 更改主要联系人
export function changeContact(id: any, userId: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/contact/' + userId,
        method: 'put',
        headers: token,
        params: { id }
    })
}

// 批量删除联系人
export function deleteContact(data: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/contact/',
        method: 'delete',
        headers: token,
        data
    })
}

// 更新客户知识库查看权限
export function updateSelectKnowledgeAuthor(id: any, params: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: `/user/updateSelectKnowledgeAuthor/${id}`,
        method: 'PUT',
        headers: token,
        params
    })
}

/**
 * 根据客户分类ID获取知识库类型权限列表
 * @param userTypeId 客户分类ID
 * @param data 搜索对象
 * @returns 
 */
export function getSelectKnowledgeAuthorList(userTypeId: any, data: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: `/user/type/knowledge/type/getList/${userTypeId}`,
        method: 'post',
        headers: token,
        data
    })
}


/* -----------基础资料相关  start ---------------  */

// 获取用户设置
export function getUserSet() {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/set/getUserSet',
        method: 'get',
        headers: token,
    })
}

// 保存用户设置
export function saveUserSet(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/set/saveUserSet',
        method: 'put',
        headers: token,
        data
    })
}

// 获取用户级别列表
export function getLevelList(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/level/getList',
        method: 'post',
        headers: token,
        data
    })
}

// 新增或修改用户级别
export function saveUserLevel(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/level/save',
        method: 'post',
        headers: token,
        data
    })
}

// 批量更改用户级别状态
export function changeLevel(data: object, status: boolean) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/level/',
        method: 'put',
        headers: token,
        data,
        params: { status }
    })
}

// 批量删除用户级别状态
export function deleteLevel(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/level/',
        method: 'delete',
        headers: token,
        data,
    })
}

// 获取用户分类列表
export function getTypeList(params: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/type/getList',
        method: 'post',
        headers: token,
        data: params
    })
}

// 新增或修改用户分类
export function saveUserType(params: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/type/save',
        method: 'post',
        headers: token,
        params
    })
}

// 批量更改用户分类状态
export function changeType(data: object, status: boolean) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/type/',
        method: 'put',
        headers: token,
        data,
        params: { status }
    })
}

// 批量删除用户分类
export function deleteType(data: object) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/type/',
        method: 'delete',
        headers: token,
        data,
    })
}

/* -----------基础资料相关  end ---------------  */
//根据工单ID获取客户关联信息
export function getUserRelationInfo(workId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/getUserRelationInfo/'+workId,
        method: 'get',
        headers: token,
    })
}
// 获取客户关联的编码商品列表
export function getUserRelationCodeGoodsList(data: object,userId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/getUserRelationCodeGoodsList/'+userId,
        method: 'post',
        headers: token,
        data,
    })
}

// 获取客户关联的工单列表
export function getUserRelationOrderList(data: object,userId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/getUserRelationOrderList/'+userId,
        method: 'post',
        headers: token,
        data,
    })
}
// 根据客户ID获取客户附件
export function getUserAnnex(userId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/annex/getUserAnnex/'+userId,
        method: 'get',
        headers: token,
    })
}
//新增或删除用户附件
export function annexSave(data,userId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/user/annex/save/'+userId,
        method: 'post',
        headers: token,
        data
    })
}
//根据知识库分类ID获取说明书
export function getInstructionBook(knowledgeTypeId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/knowledge/instruction-book/getInstructionBook/'+knowledgeTypeId,
        method: 'get',
        headers: token,
    })
}
//根据知识库分类ID获取故障库
export function getFailt(knowledgeTypeId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/knowledge/fault/getFailt/'+knowledgeTypeId,
        method: 'get',
        headers: token,
    })
}
//根据知识库分类ID获取视频
export function getVideo(knowledgeTypeId) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/knowledge/video/getVideo/'+knowledgeTypeId,
        method: 'get',
        headers: token,
    })
}
